package com.buildings.activity.table;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buildings.R;
import com.buildings.api.Api;
import com.buildings.api.Constant;
import com.buildings.base.BaseActivity;
import com.buildings.base.BaseApplication;
import com.buildings.base.JsonBean;
import com.buildings.bean.DrillHoleDbEntity;
import com.buildings.bean.DrillHoleEntity;
import com.buildings.bean.FaultTypeBean;
import com.buildings.bean.GeologicalSvyPlanningPtEntity;
import com.buildings.bean.GeomorphySvyReProfDbEntity;
import com.buildings.bean.LoginBean;
import com.buildings.http.BaseCallBack;
import com.buildings.http.JsonBuilder;
import com.buildings.http.MyHttpClient;
import com.buildings.util.CustomToast;
import com.buildings.util.DialogUtils;
import com.buildings.util.FileUtil;
import com.buildings.util.HYDialogUtils;
import com.buildings.util.HYImageUtils;
import com.buildings.util.PhotoRecycleBuild;
import com.buildings.util.SPUtil;
import com.buildings.util.StringUtil;
import com.buildings.util.TabTitleBuilder;
import com.buildings.view.ShowBottomDialog;
import com.google.gson.Gson;
import com.zr.earthquate.db.greendao.DaoSession;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

//钻孔-点
public class DrillHoleActivity extends BaseActivity {
    @BindView(R.id.ll_tab_title)
    LinearLayout llTabTitle;
    @BindView(R.id.rv_pics)
    RecyclerView rvPics;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right_text)
    TextView tvRightText;
    @BindView(R.id.ll_visibile)
    LinearLayout llVisibile;

    @BindView(R.id.et_id)
    EditText etId;
    @BindView(R.id.et_fieldid)
    EditText etFieldid;
    @BindView(R.id.et_purpose)
    EditText etPurpose;
    @BindView(R.id.tv_drilldate)
    TextView etDrilldate;
    @BindView(R.id.et_locationname)
    EditText etLocationname;
    @BindView(R.id.tv_drillsource)
    TextView tvDrillsource;
    @BindView(R.id.et_elevation)
    EditText etElevation;
    @BindView(R.id.et_depth)
    EditText etDepth;
    @BindView(R.id.et_coretotalthickness)
    EditText etCoretotalthickness;
    @BindView(R.id.et_projectid)
    EditText etProjectid;
    @BindView(R.id.et_profileid)
    EditText etProfileid;
    @BindView(R.id.et_holocenethickness)
    EditText etHolocenethickness;
    @BindView(R.id.et_uppleithickness)
    EditText etUppleithickness;
    @BindView(R.id.et_midpleithickness)
    EditText etMidpleithickness;
    @BindView(R.id.et_lowpleithickness)
    EditText etLowpleithickness;
    @BindView(R.id.et_prepleithickness)
    EditText etPrepleithickness;
    @BindView(R.id.et_samplecount)
    EditText etSamplecount;
    @BindView(R.id.et_datingsamplecount)
    EditText etDatingsamplecount;
    @BindView(R.id.tv_isgeophywell)
    TextView tvIsgeophywell;
    @BindView(R.id.et_collectedenviromentsamplecount)
    EditText etCollectedenviromentsamplecount;
    @BindView(R.id.et_enviromentsamplecount)
    EditText etEnviromentsamplecount;
    @BindView(R.id.et_testedenviromentsamplecount)
    EditText etTestedenviromentsamplecount;
    @BindView(R.id.et_columnchartAiid)
    EditText etColumnchartAiid;
    @BindView(R.id.et_columnchartArwid)
    EditText etColumnchartArwid;
    @BindView(R.id.et_corephotoArwid)
    EditText etCorephotoArwid;
    @BindView(R.id.et_commentInfo)
    EditText etCommentInfo;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.tv_visibile)
    TextView tvVisibile;

    private TabTitleBuilder tabTitleBuilder;
    private PhotoRecycleBuild photoRecycleBuild;
    private Dialog myDialog;
    private DaoSession daoSession;
    private String urlArr;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drill_hole);
        ButterKnife.bind(this);
        daoSession = BaseApplication.getInstance().getDaoSession();
        tabTitleBuilder = new TabTitleBuilder(llTabTitle, this);
        initView();
    }

    private String type;
    private String taskId = "";
    private String projectId = "";
    private String projectName = "";
    private String taskName = "";
    private boolean isOnline;
    private int joninType;
    private String uuid;
    private long _id = -1;
    Calendar calendar = Calendar.getInstance(Locale.CHINA);

    public void initView() {
        joninType = getIntent().getIntExtra("joninType", 1);
        photoRecycleBuild = new PhotoRecycleBuild(this, rvPics, joninType);
        if (joninType != 2) {
            tvTitle.setText("钻孔-点");
            tvRightText.setText("保存");
            double x = getIntent().getDoubleExtra("x", 0.0);
            double y = getIntent().getDoubleExtra("y", 0.0);
            type = getIntent().getStringExtra("type");
            taskId = getIntent().getStringExtra("taskId");
            projectId = getIntent().getStringExtra("projectId");
            projectName = getIntent().getStringExtra("projectName");
            taskName = getIntent().getStringExtra("taskName");
            isOnline = getIntent().getBooleanExtra("isOnLine", true);
            if (TextUtils.isEmpty(type)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(taskId)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(projectId)) {
                finish();
            }
            tabTitleBuilder.setLat(x);
            tabTitleBuilder.setLon(y);
            if (getIntent().hasExtra("_id")) {
                _id = getIntent().getLongExtra("_id", -1);
                setLocalData(_id);
            }
            if (1 == Constant.IS_ON_LINE) {
                btnSubmit.setVisibility(View.VISIBLE);
            } else {
                btnSubmit.setVisibility(View.GONE);
            }
        } else {
            isOnline = getIntent().getBooleanExtra("isOnLine", false);
            if (1 == Constant.IS_ON_LINE) {
                tvTitle.setText("钻孔-点详情");
                uuid = getIntent().getStringExtra("uuid");
                tabTitleBuilder.setEnabled();
                setEnableFalse();
                getDetailHttp();
                btnSubmit.setVisibility(View.GONE);
            } else {
                tvTitle.setText("钻孔-点");
                tvRightText.setText("保存");
                uuid = getIntent().getStringExtra("uuid");
                if (getIntent().hasExtra("_id")) {
                    _id = getIntent().getLongExtra("_id", -1);
                    setLocalData(_id);
                }
                btnSubmit.setVisibility(View.GONE);
            }
        }
    }

    public void setLocalData(long a) {
        if (a == -1) {
            return;
        }
        List<DrillHoleDbEntity> students = daoSession.loadAll(DrillHoleDbEntity.class);
        for (DrillHoleDbEntity drillHoleDbEntity : students) {
            if (a == drillHoleDbEntity.get_id()) {
                setDetail(drillHoleDbEntity);
            }
        }
    }

    private void setEnableFalse() {
        etId.setEnabled(false);
        etFieldid.setEnabled(false);
        etPurpose.setEnabled(false);
        etDrilldate.setEnabled(false);
        etLocationname.setEnabled(false);
        tvDrillsource.setEnabled(false);
        etElevation.setEnabled(false);
        etDepth.setEnabled(false);
        etCoretotalthickness.setEnabled(false);
        etProjectid.setEnabled(false);
        etProfileid.setEnabled(false);
        etHolocenethickness.setEnabled(false);
        etUppleithickness.setEnabled(false);
        etMidpleithickness.setEnabled(false);
        etLowpleithickness.setEnabled(false);
        etPrepleithickness.setEnabled(false);
        etSamplecount.setEnabled(false);
        etDatingsamplecount.setEnabled(false);
        tvIsgeophywell.setEnabled(false);
        etCollectedenviromentsamplecount.setEnabled(false);
        etEnviromentsamplecount.setEnabled(false);
        etTestedenviromentsamplecount.setEnabled(false);
        etColumnchartAiid.setEnabled(false);
        etColumnchartArwid.setEnabled(false);
        etCorephotoArwid.setEnabled(false);
        etCommentInfo.setEnabled(false);
    }

    @OnClick({R.id.iv_back, R.id.tv_right_text, R.id.tv_visibile, R.id.tv_drillsource
            , R.id.tv_isgeophywell, R.id.btn_submit, R.id.iv_id_hint, R.id.tv_drilldate})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_isgeophywell:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            tvIsgeophywell.setText("是");
                        } else {
                            tvIsgeophywell.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.tv_drillsource:
                FaultTypeBean faultTypeBean2 = new Gson().fromJson(JsonBean.DrillTypeCVD, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean2, "DrillTypeCVD");
                break;
            case R.id.tv_visibile:
                if (llVisibile.getVisibility() == View.VISIBLE) {
                    llVisibile.setVisibility(View.GONE);
                    tvVisibile.setText("显示更多");
                } else {
                    llVisibile.setVisibility(View.VISIBLE);
                    tvVisibile.setText("隐藏更多");
                }
                break;
            case R.id.tv_right_text:
                //TODO 调用保存表单接口
                save();
                break;
            case R.id.btn_submit:
                submit();
                break;
            case R.id.iv_id_hint:
                HYDialogUtils.showCommonAlertDialog(this, "长度17位，前9位，行政区划代码6位+3位专题号，后8位自定义编码，字母数字均可，不足8位#补齐\n" +
                                "3位专题号，用户自己设置。一般就是100，101，102...,201,202"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.tv_drilldate:
                showDatePickerDialog(calendar);
                break;
        }
    }

    /**
     * 时间选择
     *
     * @param calendar
     */

    @SuppressLint("ResourceType")
    public void showDatePickerDialog(Calendar calendar) {
        // 直接创建一个DatePickerDialog对话框实例，并将它显示出来
        new DatePickerDialog(this, 4, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                etDrilldate.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }

        }
                // 设置初始日期
                , calendar.get(Calendar.YEAR)
                , calendar.get(Calendar.MONTH)
                , calendar.get(Calendar.DAY_OF_MONTH)).show();
    }

    private void getHttpData(String type) {
        MyHttpClient
                .newBuilder()
                .get()
                .url(Api.HDD_DRILL_HOLES_TYPE + type)
                .build()
                .enqueue(new BaseCallBack<FaultTypeBean>() {
                    @Override
                    public void onSuccess(FaultTypeBean bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setFaultTypeCVD(bean, type);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                    }
                });
    }

    //断层性质数据
    private List<FaultTypeBean.DataBean> dataBeans = new ArrayList<>();

    private FaultTypeBean.DataBean trenchTypeCVDBean;

    public void setFaultTypeCVD(FaultTypeBean bean, String type) {
        dataBeans.clear();
        dataBeans.addAll(bean.getData());
        String[] arr = new String[dataBeans.size()];
        for (int i = 0; i < dataBeans.size(); i++) {
            arr[i] = dataBeans.get(i).getDictItemName();
        }
        HYDialogUtils.showSingleChoiceItemAlertDialog(this, "选择", 0, arr
                , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (type) {
                            case "DrillTypeCVD":
                                trenchTypeCVDBean = dataBeans.get(i);
                                tvDrillsource.setText(dataBeans.get(i).getDictItemName());
                                break;
                        }
                        dialogInterface.dismiss();
                    }
                });
    }

    public void save() {
        DrillHoleDbEntity bean = new DrillHoleDbEntity();
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();
        String id = etId.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String purpose = etPurpose.getText().toString().trim();
        String drilldate = etDrilldate.getText().toString().trim();
        String locationname = etLocationname.getText().toString().trim();
        String drillsource = tvDrillsource.getText().toString().trim();
        String elevation = etElevation.getText().toString().trim();
        String depth = etDepth.getText().toString().trim();
        String coretotalthickness = etCoretotalthickness.getText().toString().trim();
        String projectid = etProjectid.getText().toString().trim();
        String profileid = etProfileid.getText().toString().trim();
        String holocenethickness = etHolocenethickness.getText().toString().trim();
        String uppleithickness = etUppleithickness.getText().toString().trim();
        String midpleithickness = etMidpleithickness.getText().toString().trim();
        String lowpleithickness = etLowpleithickness.getText().toString().trim();
        String prepleithickness = etPrepleithickness.getText().toString().trim();
        String samplecount = etSamplecount.getText().toString().trim();
        String datingsamplecount = etDatingsamplecount.getText().toString().trim();
        String isgeophywell = tvIsgeophywell.getText().toString().trim();
        String collectedenviromentsamplecount = etCollectedenviromentsamplecount.getText().toString().trim();
        String enviromentsamplecount = etEnviromentsamplecount.getText().toString().trim();
        String testedenviromentsamplecount = etTestedenviromentsamplecount.getText().toString().trim();
        String columnchartAiid = etColumnchartAiid.getText().toString().trim();
        String columnchartArwid = etColumnchartArwid.getText().toString().trim();
        String corephotoArwid = etCorephotoArwid.getText().toString().trim();
        String commentInfo = etCommentInfo.getText().toString().trim();

        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入钻孔编号");
            return;
        }

        if (id.length() != 17) {
            Toast("请录入正确的钻孔编号");
            return;
        }

        bean.setProvince(province);
        bean.setCity(city);
        bean.setArea(area);
        bean.setLat(lat);
        bean.setLon(lon);
        bean.setTown(buildingAddress);

        bean.setId(id);
        bean.setFieldid(fieldid);
        bean.setPurpose(purpose);
        bean.setDrilldate(drilldate);
        bean.setLocationname(locationname);
        bean.setDrillsource(null == trenchTypeCVDBean ?
                null == drillHoleDbEntity ? "" : drillHoleDbEntity.getDrillsource() : trenchTypeCVDBean.getDictItemCode());
        bean.setDrillsourceName(drillsource);
        bean.setElevation(elevation);
        bean.setDepth(depth);
        bean.setCoretotalthickness(coretotalthickness);
        bean.setProjectId(projectid);
        bean.setProfileid(profileid);
        bean.setHolocenethickness(holocenethickness);
        bean.setUppleithickness(uppleithickness);
        bean.setMidpleithickness(midpleithickness);
        bean.setLowpleithickness(lowpleithickness);
        bean.setPrepleithickness(prepleithickness);
        bean.setSamplecount(samplecount);
        bean.setDatingsamplecount(datingsamplecount);
        bean.setIsgeophywell("是".equals(isgeophywell) ? "1" : "0");
        bean.setCollectedenviromentsamplecount(collectedenviromentsamplecount);
        bean.setEnviromentsamplecount(enviromentsamplecount);
        bean.setTestedenviromentsamplecount(testedenviromentsamplecount);
        bean.setColumnchartAiid(columnchartAiid);
        bean.setColumnchartArwid(columnchartArwid);
        bean.setCorephotoArwid(corephotoArwid);
        bean.setCommentInfo(commentInfo);
        if (Constant.IS_ON_LINE == 1) {
            bean.setProjectId(projectId);
            bean.setProjectName(projectName);
            bean.setTaskName(taskName);
            bean.setTaskId(taskId);
        }
        if (photoRecycleBuild.getSrcList().size() != 0) {
            String url = "";
            for (int i = 0; i < photoRecycleBuild.getSrcList().size(); i++) {
                if (TextUtils.isEmpty(url)) {
                    url = FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                } else {
                    url = url + "," + FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                }
            }
            bean.setExtends7(url);
        }
        if (-1 != _id) {
            bean.set_id(_id);
        }
        daoSession.insertOrReplace(bean);
        CustomToast.showToast(this, "保存成功");
        finish();
    }

    public void submit() {
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();
        String id = etId.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String purpose = etPurpose.getText().toString().trim();
        String drilldate = etDrilldate.getText().toString().trim();
        String locationname = etLocationname.getText().toString().trim();
        String drillsource = tvDrillsource.getText().toString().trim();
        String elevation = etElevation.getText().toString().trim();
        String depth = etDepth.getText().toString().trim();
        String coretotalthickness = etCoretotalthickness.getText().toString().trim();
        String projectid = etProjectid.getText().toString().trim();
        String profileid = etProfileid.getText().toString().trim();
        String holocenethickness = etHolocenethickness.getText().toString().trim();
        String uppleithickness = etUppleithickness.getText().toString().trim();
        String midpleithickness = etMidpleithickness.getText().toString().trim();
        String lowpleithickness = etLowpleithickness.getText().toString().trim();
        String prepleithickness = etPrepleithickness.getText().toString().trim();
        String samplecount = etSamplecount.getText().toString().trim();
        String datingsamplecount = etDatingsamplecount.getText().toString().trim();
        String isgeophywell = tvIsgeophywell.getText().toString().trim();
        String collectedenviromentsamplecount = etCollectedenviromentsamplecount.getText().toString().trim();
        String enviromentsamplecount = etEnviromentsamplecount.getText().toString().trim();
        String testedenviromentsamplecount = etTestedenviromentsamplecount.getText().toString().trim();
        String columnchartAiid = etColumnchartAiid.getText().toString().trim();
        String columnchartArwid = etColumnchartArwid.getText().toString().trim();
        String corephotoArwid = etCorephotoArwid.getText().toString().trim();
        String commentInfo = etCommentInfo.getText().toString().trim();

        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入钻孔编号");
            return;
        }

        if (id.length() != 17) {
            Toast("请录入正确的钻孔编号");
            return;
        }

        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        DialogUtils.showIOSDialog(activity, "提示", "", "", "", ""
                , new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (null != myDialog)
                            myDialog.dismiss();
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        submit();
                        photoRecycleBuild.submitImage(photoRecycleBuild.getSrcList(), 1, new PhotoRecycleBuild.ImageCallBack() {
                            @Override
                            public void onCallBack(String url) {
                                DrillHoleActivity.this.urlArr = url;

                                JsonBuilder jsonBuilder = new JsonBuilder(DrillHoleActivity.this);
                                jsonBuilder.put("province", province);
                                jsonBuilder.put("city", city);
                                jsonBuilder.put("area", area);
                                jsonBuilder.put("lat", lon);
                                jsonBuilder.put("lon", lat);
                                jsonBuilder.put("town", buildingAddress);
                                jsonBuilder.put("type", type);
                                jsonBuilder.put("taskId", taskId);
                                jsonBuilder.put("projectId", projectId);
                                jsonBuilder.put("projectName", projectName);
                                jsonBuilder.put("taskName", taskName);
                                jsonBuilder.put("userId", SPUtil.get("userId", ""));
                                jsonBuilder.put("id", id);
                                jsonBuilder.put("fieldid", fieldid);
                                jsonBuilder.put("purpose", purpose);
                                jsonBuilder.put("drilldate", drilldate);
                                jsonBuilder.put("locationname", locationname);
                                jsonBuilder.put("drillsource", null == trenchTypeCVDBean
                                        ? null == drillHoleDbEntity ? "" : drillHoleDbEntity.getDrillsource() : trenchTypeCVDBean.getDictItemCode());
                                jsonBuilder.put("drillsourceName", drillsource);
                                jsonBuilder.put("elevation", elevation);
                                jsonBuilder.put("depth", depth);
                                jsonBuilder.put("coretotalthickness", coretotalthickness);
                                jsonBuilder.put("projectid", projectid);
                                jsonBuilder.put("profileid", profileid);
                                jsonBuilder.put("holocenethickness", holocenethickness);
                                jsonBuilder.put("uppleithickness", uppleithickness);
                                jsonBuilder.put("midpleithickness", midpleithickness);
                                jsonBuilder.put("lowpleithickness", lowpleithickness);
                                jsonBuilder.put("prepleithickness", prepleithickness);
                                jsonBuilder.put("samplecount", samplecount);
                                jsonBuilder.put("datingsamplecount", datingsamplecount);
                                jsonBuilder.put("isgeophywell", "是".equals(isgeophywell) ? 1 : 0);
                                jsonBuilder.put("collectedenviromentsamplecount", collectedenviromentsamplecount);
                                jsonBuilder.put("enviromentsamplecount", enviromentsamplecount);
                                jsonBuilder.put("testedenviromentsamplecount", testedenviromentsamplecount);
                                jsonBuilder.put("columnchartAiid", columnchartAiid);
                                jsonBuilder.put("columnchartArwid", columnchartArwid);
                                jsonBuilder.put("corephotoArwid", corephotoArwid);
                                jsonBuilder.put("commentInfo", commentInfo);
                                jsonBuilder.put("extends7", urlArr);
                                jsonBuilder.put("createUser", SPUtil.get("userId", ""));
                                MyHttpClient
                                        .newBuilder()
                                        .post()
                                        .url(Api.HDD_DRILL_HOLES)
                                        .addParam(jsonBuilder.toJsonString())
                                        .build()
                                        .enqueue(new BaseCallBack<LoginBean>() {
                                            @Override
                                            public void onSuccess(LoginBean bean) {
                                                super.onSuccess(bean);
                                                if (bean.getCode() == 200) {
                                                    if (-1 != _id && null != drillHoleDbEntity) {
                                                        try {
                                                            daoSession.delete(drillHoleDbEntity);
                                                        } catch (Exception e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                    CustomToast.showToast(DrillHoleActivity.this, "提交成功");
                                                    finish();
                                                }
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                            }

                                            @Override
                                            public void onFailure(Call call, IOException e) {
                                                super.onFailure(call, e);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                                            }

                                            @Override
                                            public void onError(int code) {
                                                super.onError(code);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                                            }
                                        });
                            }
                        });
                    }
                }, "提交后不能再修改");

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case HYImageUtils.REQUEST_CODE_FROM_CAMERA:
                List<Uri> list_1 = new ArrayList<>();
                list_1.add(HYImageUtils.imageUriFromCamera);
                photoRecycleBuild.updataAdapter(list_1);
                break;
            case HYImageUtils.REQUEST_CODE_FROM_ALBUM:
                ArrayList<String> files = data.getStringArrayListExtra("files");
                if (files == null || files.size() == 0) {
                    return;
                }
                List<Uri> list_2 = new ArrayList<>();
                for (String file : files) {
                    list_2.add(Uri.fromFile(new File(file)));
                }
                photoRecycleBuild.updataAdapter(list_2);
                // submitImage(list_2, correctTypeListEntity.getFieldList().get(lastClickItemPosition));
                break;
        }
    }

    public void getDetailHttp() {
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        String url = Api.HDD_DRILL_HOLES + "/" + uuid;
        MyHttpClient
                .newBuilder()
                .get()
                .url(url)
                .build()
                .enqueue(new BaseCallBack<DrillHoleEntity>() {
                    @Override
                    public void onSuccess(DrillHoleEntity bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setDetailData(bean);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(DrillHoleActivity.this, "网络异常");
                    }
                });
    }

    private void setDetailData(DrillHoleEntity bean) {
        tabTitleBuilder.setDetailText(bean.getData().getProvince(), bean.getData().getCity()
                , bean.getData().getArea(), bean.getData().getLat(), bean.getData().getLon(), bean.getData().getTown());

        etId.setText(StringUtil.isNull(bean.getData().getId()));
        etFieldid.setText(StringUtil.isNull(bean.getData().getFieldid()));
        etPurpose.setText(StringUtil.isNull(bean.getData().getPurpose()));
        etDrilldate.setText(StringUtil.isNull(bean.getData().getDrilldate()));
        etLocationname.setText(StringUtil.isNull(bean.getData().getLocationname()));
        tvDrillsource.setText(StringUtil.isNull(bean.getData().getDrillsourceName()));
        etElevation.setText(StringUtil.isNull(bean.getData().getElevation()));
        etDepth.setText(StringUtil.isNull(bean.getData().getDepth()));
        etCoretotalthickness.setText(StringUtil.isNull(bean.getData().getCoretotalthickness()));
        etProjectid.setText(StringUtil.isNull(bean.getData().getProjectId()));
        etProfileid.setText(StringUtil.isNull(bean.getData().getProfileid()));
        etHolocenethickness.setText(StringUtil.isNull(bean.getData().getHolocenethickness()));
        etUppleithickness.setText(StringUtil.isNull(bean.getData().getUppleithickness()));
        etMidpleithickness.setText(StringUtil.isNull(bean.getData().getMidpleithickness()));
        etLowpleithickness.setText(StringUtil.isNull(bean.getData().getLowpleithickness()));
        etPrepleithickness.setText(StringUtil.isNull(bean.getData().getPrepleithickness()));
        etSamplecount.setText(StringUtil.isNull(bean.getData().getSamplecount()));
        etDatingsamplecount.setText(StringUtil.isNull(bean.getData().getDatingsamplecount()));
        tvIsgeophywell.setText("1".equals(bean.getData().getIsgeophywell()) ? "是" : "否");
        etCollectedenviromentsamplecount.setText(StringUtil.isNull(bean.getData().getCollectedenviromentsamplecount()));
        etEnviromentsamplecount.setText(StringUtil.isNull(bean.getData().getEnviromentsamplecount()));
        etTestedenviromentsamplecount.setText(StringUtil.isNull(bean.getData().getTestedenviromentsamplecount()));
        etColumnchartAiid.setText(StringUtil.isNull(bean.getData().getColumnchartAiid()));
        etColumnchartArwid.setText(StringUtil.isNull(bean.getData().getColumnchartArwid()));
        etCorephotoArwid.setText(StringUtil.isNull(bean.getData().getCorephotoArwid()));
        etCommentInfo.setText(StringUtil.isNull(bean.getData().getCommentInfo()));
        photoRecycleBuild.setHttpUrl(bean.getData().getExtends7());
    }

    private DrillHoleDbEntity drillHoleDbEntity;

    private void setDetail(DrillHoleDbEntity bean) {
        this.drillHoleDbEntity = bean;
        tabTitleBuilder.setDetailText(bean.getProvince(), bean.getCity()
                , bean.getArea(), bean.getLat(), bean.getLon(), bean.getTown());

        etId.setText(StringUtil.isNull(bean.getId()));
        etFieldid.setText(StringUtil.isNull(bean.getFieldid()));
        etPurpose.setText(StringUtil.isNull(bean.getPurpose()));
        etDrilldate.setText(StringUtil.isNull(bean.getDrilldate()));
        etLocationname.setText(StringUtil.isNull(bean.getLocationname()));
        tvDrillsource.setText(StringUtil.isNull(bean.getDrillsourceName()));
        etElevation.setText(StringUtil.isNull(bean.getElevation()));
        etDepth.setText(StringUtil.isNull(bean.getDepth()));
        etCoretotalthickness.setText(StringUtil.isNull(bean.getCoretotalthickness()));
        etProjectid.setText(StringUtil.isNull(bean.getProjectId()));
        etProfileid.setText(StringUtil.isNull(bean.getProfileid()));
        etHolocenethickness.setText(StringUtil.isNull(bean.getHolocenethickness()));
        etUppleithickness.setText(StringUtil.isNull(bean.getUppleithickness()));
        etMidpleithickness.setText(StringUtil.isNull(bean.getMidpleithickness()));
        etLowpleithickness.setText(StringUtil.isNull(bean.getLowpleithickness()));
        etPrepleithickness.setText(StringUtil.isNull(bean.getPrepleithickness()));
        etSamplecount.setText(StringUtil.isNull(bean.getSamplecount()));
        etDatingsamplecount.setText(StringUtil.isNull(bean.getDatingsamplecount()));
        tvIsgeophywell.setText("1".equals(bean.getIsgeophywell()) ? "是" : "否");
        etCollectedenviromentsamplecount.setText(StringUtil.isNull(bean.getCollectedenviromentsamplecount()));
        etEnviromentsamplecount.setText(StringUtil.isNull(bean.getEnviromentsamplecount()));
        etTestedenviromentsamplecount.setText(StringUtil.isNull(bean.getTestedenviromentsamplecount()));
        etColumnchartAiid.setText(StringUtil.isNull(bean.getColumnchartAiid()));
        etColumnchartArwid.setText(StringUtil.isNull(bean.getColumnchartArwid()));
        etCorephotoArwid.setText(StringUtil.isNull(bean.getCorephotoArwid()));
        etCommentInfo.setText(StringUtil.isNull(bean.getCommentInfo()));
        if (!TextUtils.isEmpty(bean.getExtends7())) {
            String[] arr = bean.getExtends7().split(",");
            List<Uri> list = new ArrayList<>();
            for (int i = 0; i < arr.length; i++) {
                File file = new File(arr[i]);
                Uri uri = Uri.fromFile(file);
                list.add(uri);
            }
            photoRecycleBuild.updataAdapter(list);
        }
    }
}
